home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 78 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.0 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: Eugene Lazutkin <eugene@int.com>
  3. Newsgroups: comp.std.c++
  4. Subject: FW: Inherent C++ problem?
  5. Date: 19 Jan 1996 16:41:16 PST
  6. Organization: -
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <01BAE696.8C249300@dino.int.com>
  9. NNTP-Posting-Host: isolde.mti.sgi.com
  10. X-Original-Date: Fri, 19 Jan 1996 17:49:55 -0600
  11. Encoding: 50 TEXT
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBVAwUBMQA6Uky4NqrwXLNJAQFmWAH+ObzxtNJDt8WxrYXvQdJc01fc68JAkAPu
  14.     p915MSOkZWVYZR+Rwsjm+N9NwG1AP9clzrKXJDGy9hEJNzc4X3bnrw==
  15.     =9E4H
  16. Originator: austern@isolde.mti.sgi.com
  17.  
  18. ----------
  19. From:     Max Motovilov[SMTP:max@int.com]
  20. Sent:     Friday, January 19, 1996 4:01 PM
  21. To:     'Eugene Lazutkin'
  22. Subject:     (for comp.std.c++)  Inherent C++ problem?
  23.  
  24. Looks like Subj to me, but maybe I misunderstand something or overlooking a 
  25. simple workaround...
  26.  
  27. Here is the example:
  28.  
  29.     struct    Complex
  30.     {
  31.         double re, im;
  32.  
  33.         Complex( double r, double i ) : re( r ), im( i ) {}
  34.         Complex( const Complex& c ) : re( c.re ), im( c.im ) {}
  35.     };
  36.  
  37.     Complex    operator + ( const Complex& a, const Complex& b )
  38.     {
  39.         return Complex( a.re+b.re, a.im+b.im );
  40.     }
  41.  
  42. It is all right by now. Consider the following use then:
  43.  
  44.     Complex a( 1, 0 ), b( 0, 1 );
  45.     Complex c( a+b );
  46.  
  47. In the last line 3 objects of type Complex are constructed instead of 1, 
  48. namely:
  49.  
  50. 1) Temporary Complex object constructed in 'operator +'
  51. 2) Return value of 'operator +' copy-constructed from (1)
  52. 3) 'c', copy-constructed from (2)
  53.  
  54. This is inefficient to the last extreme, moreover it cannot even be 
  55. optimized out since any copy-constructor can theoretically have non-local 
  56. side effects....
  57.  
  58. To me, the step (2) can be eliminated by certain amendment to the semantics 
  59. of the language while (3) seems to be inherent. I wonder though if 
  60. something could be done about it within the bounds of the current 
  61. standard...
  62.  
  63. Regards,
  64. ...Max...
  65. ---
  66. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  67.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  68.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  69.